<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="fragments/easyui_insdep_head :: easyui_insdep_head" th:with="title='员工管理'">
</head>
<body>

<table id="tt" class="easyui-datagrid" style="width:100%;height:100%" method="get"
       url="/staff/list" toolbar="#tb" pageList='[1,10,20,30,50]' singleSelect="true"
       rownumbers="true" pagination="true">
    <thead>
    <tr>
        <th field="staffId" width="80">职工ID</th>
        <th field="staffName" width="80">职工姓名</th>
    </tr>
    </thead>
</table>

<div id="tb" style="padding:3px">
    <span>职工ID:</span>
    <input id="staffId" style="line-height:26px;border:1px solid #ccc"/>
    <span>职工姓名:</span>
    <input id="staffName" style="line-height:26px;border:1px solid #ccc"/>
    <input type="checkbox" id="isFuzzy" checked="checked" />模糊查询
    <a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()">查找</a>
    <a href="#" class="easyui-linkbutton" plain="true" onclick="doReSet()">重置</a>
    <script type="text/javascript">
        //<![CDATA[
        function doSearch() {
            param = {};
            if ($('#staffId').val())
                param.staffId = $('#staffId').val();
            if ($('#staffName').val())
                param.staffName = $('#staffName').val();
            param.isFuzzy = $('#isFuzzy').is(':checked');

            $('#tt').datagrid('load', param);
        }
        function doReSet() {
            $('#staffId').val("");
            $('#staffName').val("");
            if (!$('#isFuzzy').is(':checked')) {
                $('#isFuzzy').click();
            }
            doSearch();
        }
        //]]>
    </script>
</div>

<div id="ajaxWin" class="easyui-window" title=""
     data-options="modal:true,collapsible:true,closed:true,maximizable:false,minimizable:false,resizable:false"
     style="width:600px;height:500px;overflow: hidden">
    <iframe id="frame" frameborder="0" style="height:100%;width:100%; "/>
</div>


<script type="text/javascript">
    //<![CDATA[
    $(function () {
        $('#ajaxWin').window({
            onBeforeClose: function () { //当面板关闭之前触发的事件
                $("#tt").datagrid("reload");
            }
        });

        var pager = $('#tt').datagrid().datagrid('getPager');	// get the pager of datagrid
        pager.pagination({
            buttons: [{
                iconCls: 'icon-add',
                handler: function () {
                    windowOpen("增加员工", "/staff/pages/staffAddPage");
                }
            }, {
                iconCls: 'icon-edit',
                handler: function () {
                    row = $("#tt").datagrid('getSelected');

                    if (row == null) {
                        $.messager.alert('警告', '请选中需要修改的职工', 'info');
                        return;
                    }

                    windowOpen("修改员工信息", "/staff/pages/staffUpdatePage?staffId=" + row.staffId + "&staffName=" + row.staffName);
                }
            }, {
                iconCls: 'icon-remove',
                handler: function () {
                    row = $("#tt").datagrid('getSelected');

                    if (row == null) {
                        $.messager.alert('警告', '请选中需要删除的职工', 'info');
                        return;
                    }

                    $.messager.confirm('警告', '确定删除该职工吗', function (r) {
                        if (r) {
                            $.ajax({
                                url: "/staff/" + row.staffId,
                                type: "DELETE",
                                success: function (data) {
                                    var data = data == "success" ? "删除成功" : "删除失败";
                                    $.messager.alert('结果', data, 'info');
                                    $("#tt").datagrid("reload");
                                }
                            });
                        }
                    });
                }
            }]
        });


    });

    function windowOpen(title, ajax_url) {
        $('#ajaxWin').panel({title: title});

        $("#frame").attr("src", ajax_url);

        $('#ajaxWin').window('open');
    }

    //]]>
</script>


</body>
</html>